<template>
  <div class="wrapper">
    <swiper :options="swiperOptions" v-if="showSwiper">
      <swiper-slide v-for="item of list" :key="item.id">
        <img :src="item.imgUrl" class="swiper-img" alt="" />
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  props: {
    list: Array,
  },
  data() {
    return {
      swiperOptions: {
        pagination: ".swiper-pagination",
        loop: true,
      },
    };
  },
  // 如果list数组为空，则不显示swiper组件
  computed: {
    showSwiper() {
      return this.list?.length || 0;
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .swiper-pagination-bullet-active {
  background-color: #fff;
}
.wrapper {
  width: 100%;
  height: 0;
  overflow: hidden;
  padding-bottom: 30.48%;
  background-color: #ccc;
}
.swiper-img {
  width: 100%;
}
</style>